/**
 * 获取浏览器参数
 */
export const getParams = (key) => {
    let href = window.location.href.replace(/&#38;/g, '&');
  　let reg = new RegExp(`(^|\\?|&)${key}=([^&]*)(\\s|&|$)`, 'i');
　　if (reg.test(href)) {
 return unescape(RegExp.$2.replace(/\+/g, ' ')); 
}
　　return '';
};

/**
 * 固定列后滚动条滚动bug处理
 */
export const devScroll = (obj) => {
  // console.log(obj);
  if (obj.length == 0) {
    return;
  }
  let boxwrp = obj[0];
  let box = document.getElementById('box');
  // 兼容firefox
  if (boxwrp.addEventListener) {
    document.addEventListener('DOMMouseScroll', fn, false);
  }
  document.onmousewheel = fn;// 兼容IE、chrome

  function fn(ev) {
    var ev = ev || event;
    let bool = false;
    let scrollh = 0;
    // IE、chrome 向上：120，向下：-120
    // console.log(ev);
    if (ev.wheelDelta) {
      bool = ev.wheelDelta > 0;
    }
    // firefox 向上：-3，向下：3
    else {
      bool = ev.detail < 0;
    }
    scrollh = bool ? -40 : 40;
    obj.scrollTop(obj.scrollTop() + scrollh);
  }
};

/**
 * 分页返回数据处理
 */
export const getPageData = (data) => {
  if (data) {
    for (let i = 0, l = data.length; i < l; i++) {
  　　for (let key in data[i]) {
          data[i][key] = <span className="tdspan" dangerouslySetInnerHTML={{ __html: data[i][key] }} />;
  　　}
    }
    return data;
  }
  return [];
};

/**
 * 千分位转化
 */
export const comdify = (num) => {
    let reg = /\d{1,3}(?=(\d{3})+$)/g;
    return (`${num}`).replace(reg, '$&,');
};

/**
 * 初始化页面实际高度
 */
export const initHeight = (_this) => {
    let header = document.getElementsByClassName('e9theme-layout-header')[0];
    if (header) {
      _this.setState({ height: this.getHeight(header) });
    }
};

export const getHeight = (header) => {
    let h = 0;
    if (header) {
        h = header.clientHeight || 0;
    }
    return window.innerHeight - h;
};
